package day07test;

import java.util.Random;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = arr(5);
        while (true) {
            System.out.println();
            System.out.println("1.求和，，2.平均数");
            int number = sc.nextInt();
            switch (number) {
                case 1 -> {
                    int sum = sum(arr);
                    System.out.println(sum);
                }
                case 2 -> {
                    int avg = avg(arr);
                    System.out.println(avg);
                }
                default -> System.out.println("没有这个选项");
            }
        }
    }

    public static int[] arr(int len) {
        int[] arr = new int[len];
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            int random = r.nextInt(100) + 1;
            arr[i] = random;
            System.out.print(arr[i] + " ");
        }
        return arr;
    }

    //求和
    public static int sum(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum = sum + arr[i];
        }
        return sum;
    }

    //求平均数
    public static int avg(int[] arr) {
        int max = arr[0];
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            max = arr[0] > max ? max = arr[0] : max;
            min = arr[0] < min ? min = arr[0] : min;
        }
        return (int) (sum(arr) - max - min) / (arr.length - 2);
    }
}
